﻿<%@ Page Title="Manual Grading" Language="C#" MasterPageFile="~/Site.Master" AutoEventWireup="true" CodeBehind="ManualGrading.aspx.cs" Inherits="Testify.ManualGrading" %>
<%@ MasterType VirtualPath="~/Site.Master" %>

<asp:Content ID="Content1" ContentPlaceHolderID="HeadContent" runat="server">
</asp:Content>
<asp:Content ID="Content2" ContentPlaceHolderID="MainContent" runat="server">
<div class="container">
    <asp:GridView ID="grdUngradedResponses" runat="server" AutoGenerateColumns="False" DataSourceID="dsUngradedResponses" DataKeyNames="student_id,question_id"
        EmptyDataText="There are no Responses that require manual grading." >
        <Columns>
            <asp:BoundField DataField="question" HeaderText="Question" SortExpression="question" />
            <asp:BoundField DataField="answer" HeaderText="Answer" SortExpression="answer" />
            <asp:BoundField DataField="response" HeaderText="Response" SortExpression="response" />
            <asp:TemplateField HeaderText="Credit">
                <ItemTemplate>
                    <asp:TextBox ID="txtCredit" runat="server" Columns="3" style="text-align: right;" />
                    <asp:FilteredTextBoxExtender ID="fteCredit" runat="server" FilterType="Numbers" FilterMode="ValidChars" TargetControlID="txtCredit" />
                </ItemTemplate>
            </asp:TemplateField>
            <asp:TemplateField>
                <ItemTemplate>
                    <asp:Label ID="lblError" runat="server" Visible="false" ForeColor="Red" />
                </ItemTemplate>
            </asp:TemplateField>
        </Columns>
    </asp:GridView>
    <asp:SqlDataSource ID="dsUngradedResponses" runat="server" ConnectionString="<%$ ConnectionStrings:ConnectionString %>" 
        ProviderName="<%$ ConnectionStrings:ConnectionString.ProviderName %>" SelectCommand="
SELECT r.student_id, r.question_id,
       '[' || q.question_weight || '] ' || q.question_text AS question, c.choice_text AS answer,
       NVL(rc.choice_text, r.response_text) AS response
  FROM section s
       JOIN assignment a ON (a.section_id = s.section_id)
            JOIN response r ON (r.assignment_id = a.assignment_id)
                 JOIN question q ON (q.question_id = r.question_id)
                      LEFT JOIN choice c ON (c.choice_id = q.answer_id)
                 LEFT JOIN choice rc ON (rc.choice_id = r.choice_id)
 WHERE s.teacher_id = :p_TeacherID
   AND r.response_credit IS NULL
   AND (SELECT cls.term_id FROM class cls WHERE cls.class_id = s.class_id) = (SELECT current_term_id FROM environment)
   AND (c.choice_maint IS NULL OR rc.choice_maint IS NULL OR 'D' NOT IN (c.choice_maint, q.question_maint, rc.choice_maint, s.section_maint))" >
        <SelectParameters>
            <asp:SessionParameter Name="p_TeacherID" SessionField="UserID" />
        </SelectParameters>
    </asp:SqlDataSource>

    <asp:Button ID="btnSave" runat="server" Text="Save" onclick="btnSave_Click" CssClass="smallButton" />
</div>
</asp:Content>